我正在尝试测试一个rake任务,它在其中使用了一个事件记录。require'spec_helper'require'rake'loadFile.join(Rails.root,'lib','tasks','survey.rake')describe"surveyraketasks"dodescribe"survey:send_report"doit"shouldsendareport"doRake::Task['survey:send_report'].invokeendendend当我运行此规范rspecspec/lib/survey_spec.rb时,出现此错误“RuntimeEr
所以我希望我的Rails应用程序实例能够在我正在玩的“我在玩”这类东西上自行注册,并且我希望它能够提及它正在运行的本地端口。我似乎找不到如何做到这一点-事实上,只是找出它的IP是棘手的,需要一点技巧。但没问题,我有IP-但我如何才能找到我的mongrel/thin/webrick服务器正在运行的端口?非常明确地说,如果我使用script/server-p3001启动Rails应用程序,我该怎么做才能将3001拉入应用程序。 最佳答案 您可以调用Rails::Server.new.options[:Port]来获取运行Rails服务器
我最近升级到了OSMountainLion。我正在处理的项目需要gemsys-proctable作为依赖项,但是当我运行bundleinstall时,我得到:Fetchinggemmetadatafromhttps://rubygems.org/............Installingsys-proctable(0.9.2)withnativeextensionsGem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension./Users/mgriffel/.rvm/rubies/ruby-1.9.
我有一个方法可以做这样的事情:defsome_methodchance=rand(4)ifchance==1do#logichereelse#anotherlogichereendend当我用RSpec测试这个方法时,里面的rand(4)总是生成0。我不是在测试Rails的rand方法,我是在测试我的方法.测试我的方法的常见做法是什么? 最佳答案 我会考虑两种方法:方法1:在before:eachblock中使用srand(seed)中已知的种子值:before:eachdosrand(67809)end这适用于所有Ruby版本,并
尝试让克隆的Rails应用程序运行。运行bundleinstall时出现此错误:Usingmini_portile(0.5.0)Installingnokogiri(1.6.0)Gem::InstallError:nokogirirequiresRubyversion>=1.9.2.Anerroroccurredwhileinstallingnokogiri(1.6.0),andBundlercannotcontinue.Makesurethat`geminstallnokogiri-v'1.6.0'`succeedsbeforebundling.但这是rbenvversion的输出:
我看到我可以像这样用rspec测试路由:get("/").shouldroute_to("welcome#index")但我有基于主机名或部分主机名的约束,并在多个主机名之间重定向。测试时如何指定主机名?如何使用正确的配置运行测试?我尝试打印root_url并得到:Missinghosttolinkto!Pleaseprovidethe:hostparameter,setdefault_url_options[:host],orset:only_pathtotrue 最佳答案 同样的错误发生在我每次运行rspecspec/整个错误实
我正在寻求使我的Rails测试更快。我只有520个测试,但它们在bash中运行需要62秒,在Rubymine中运行需要82秒。作为典型Controller测试的示例,我使用此代码以@user身份登录并在CommentsController中为我的RSpecController测试创建基本的@comment:before(:each)do@user=Factory.create(:user)sign_in@user@comment=Factory.create(:comment)end您可能会意识到...这很慢。它构建了一个@user,但也为该用户构建了关联。@comment也是如此。所
Ruby是否有明确的规范,类似于Java的Java语言规范。谷歌搜索ruby语言规范提供http://ruby-std.netlab.jp/结果,该站点已关闭,我不确定它是否是最新的 最佳答案 有adraft对于formalspecificationruby。它由OpenStandardsPromotionCenter开发的Information-TechnologyPromotionAgency(日本政府机构)提交给JapaneseIndustrialStandardsCommittee然后进一步到InternationalO
我有以下类(class):我想确保类url只为所有实例设置一次。classDataFactory@@url=nildefinitialize()beginif@@url.nil?Rails.logger.debug"Settingurl"@@url=MY_CONFIG["myvalue"]endrescueExceptionraiseDataFactoryError,"Error!"endendend我有两个测试:it"shouldlogamessage"doAPP_CONFIG={"myvalue"=>"test"}Rails.stub(:logger).and_return(log
在设计文档中,他们提供了有关在测试Controller时如何访问current_user的提示:https://github.com/plataformatec/devise/wiki/How-To:-Test-controllers-with-Rails-3-and-4-%28and-RSpec%29但是,在进行功能测试时呢?我正在尝试测试我的一个Controller的创建方法,并且在该Controller中使用了current_user变量。问题是devise中建议的宏使用了@request变量,并且对于功能规范来说它是nil。什么是解决方法?编辑:这是我目前的规范:feature